#ifndef CARDS_H
#define CARDS_H

#include <QListView>
#include <QStandardItemModel>
#include <QLabel>
#include <QPushButton>
#include "State.h"

enum CARD_TYPE{SOLDIER, CANON, HORSE, JOKER};

struct Card
{
    Card(State* st, Player* ply) : state(st), owner(ply)
    {
        static size_t ID = 0;

        if(!(ID%3))
            type = SOLDIER;
        else if (!(ID%2))
            type = HORSE;
        else
            type = CANON;

        if(!((94-ID)%3))
            color = qRgb(0, 255, 0);
        else if (!((94-ID)%2))
            color = qRgb(255, 0, 0);
        else
            color = qRgb(0, 0, 255);

        ++ID;
    }

    State* state;
    Player* owner;
    CARD_TYPE type;
    QColor color;
    bool isJoker() const { return type == JOKER; }
};

class Cards : public QWidget
{
    Q_OBJECT
    public:
        Cards(QWidget* parent = NULL);
        ~Cards();

        void addCard(State* state);
        bool changeCardOwner(const State* state, Player* owner);
        void setWatcher(Player* ply) { m_watcher = ply; refresh(); }
        bool playerGotCard(const State* state, const Player* ply) const;

    private slots:

        void bonus();
    signals:

        void reinforcementsAdded();

    private:

        void refresh();

        Player* m_watcher;

        QList <Card*> m_cards;
        QListView *m_view;
        QStandardItemModel *m_model;
        QPushButton* m_bonus;
        QLabel* m_bonusLabel;

        size_t m_bonusCount;

        QIcon m_soldier;
        QIcon m_horse;
        QIcon m_canon;
};

#endif
